import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';

import { CommonHttpService } from './common/common-http-service';
@Injectable()
export class PhoneService extends CommonHttpService{
  constructor(public httpClient: HttpClient
  ) {
    super(httpClient);
    console.log(httpClient);
  }

  /**
   * 获取验证码
   * @param {string} phoneNum
   * @returns {Observable<any>}
   */
  public postCode(phoneNum:string ):Observable<any>{
    let url=`service/smsCode`;
    var map = {};
    if (phoneNum && phoneNum != undefined) {
      map['phone']= phoneNum;
    }
    return this.post1(url,map);
  }

  /**
   * 提交手机验证
   * @param {string} phoneNum
   * @param {string} code
   * @returns {Observable<any>}
   */
  public verifySmsCode(phoneNum:string,code:string ):Observable<any>{
    let url=`service/verifySmsCode`;
    var map = {};
    if (phoneNum && phoneNum != undefined) {
      map['phone']= phoneNum;
    }

    if (code && code != undefined) {
      map['verify']= code;
    }
    // const formdata = new FormData();
    // if (phoneNum && phoneNum != undefined) {
    //   formdata.append('phone', phoneNum);
    // }
    // if (code && code != undefined) {
    //   formdata.append('verify', code);
    // }
    return this.post1(url,map);
  }

  public bindPhone(phoneNum:string ):Observable<any>{
    let url=`service/phoneBind`;
    var map = {};
    if (phoneNum && phoneNum != undefined) {
      map['phone']= phoneNum;
    }

    // const formdata = new FormData();
    // if (phoneNum && phoneNum != undefined) {
    //   formdata.append('phone', phoneNum);
    // }
    return this.put(url,map);
  }
}
